$(function(){
    $.fn.extend({
        dialog:function(options){
            if(typeof(options)=="object"){
                var opts={title:'',
                     btnName:'确定',
                     btnBind:null,
                    size : ''
                };
                for(var prop in opts){
                    opts[prop]=options[prop]||opts[prop];
                }
                var title=opts["title"];
                var btnName=opts["btnName"];
                var template=`<div class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">${title}</h4>
                    </div>
                    <div class="modal-body">
               
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary">${btnName}</button>
                    </div>
                </div>
            </div>
        </div>`;
                var $el=$(template);
                $el.find(".modal-body").append(this);
                $el.find(".modal-content").addClass(opts.size);
                $el.find(":button:last").off("click").on("click",opts.btnBind);
                $el.appendTo("body");
            }else if("open"==options){
                this.parents(".modal").modal("show");
            }else if("close"==options){
                this.parents(".modal").modal("hide");
            }


        }
    });
});